/*
 * soundEraser.cpp
 *
 *  Created on: Jul 25, 2013
 *      Author: Hercules
 */

#include "SoundEraser.h"

std::queue<Sound*, std::deque<Sound*> > SoundEraser::_soundsToErase;
Timer SoundEraser::_waitToErase;
bool SoundEraser::_queueEmpty = true;

void SoundEraser::eraseSound(Sound* toErase) {
	_soundsToErase.push(toErase);
	if (_queueEmpty) {
		_waitToErase.start(WAIT_TO_ERASE);
		_queueEmpty = false;
	}
}
void SoundEraser::cleanUp() {
	while (!_soundsToErase.empty()) {
		delete (_soundsToErase.front());
		_soundsToErase.pop();
	}
}
void SoundEraser::update() {
	if (_soundsToErase.empty()) {
		_queueEmpty = true;
	}
	if (!_queueEmpty) {
		_waitToErase.update();
		if (_waitToErase.isDone()) {
			delete (_soundsToErase.front());
			_soundsToErase.pop();
			_waitToErase.start(WAIT_TO_ERASE);
		}
	}
}

